/**
 * 违章条款类型 编辑页
 *
 * 作者 admin
 * 日期 2024-08-08 13:20:26
 */
layui.use(['jquery', 'febs', 'form', 'validate'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        $view = $('#peccancyClause-edit'),
        validate = layui.validate;

    form.verify(validate);
    form.render();
    initFormValue();

    function initFormValue() {
        if (peccancyClauseData) {
            form.val("peccancyClause-edit-form", {
                "clauseId": peccancyClauseData.clauseId,
                "tenantId": peccancyClauseData.tenantId,
                "clauseName": peccancyClauseData.clauseName,
                "useScope": peccancyClauseData.useScope,
                // "status": peccancyClauseData.status,
                "sort": peccancyClauseData.sort,
            });
            if (peccancyClauseData.status === '1') {
                $view.find('input[type=checkbox]').attr("checked", "true");
                form.render('checkbox');
            }
        } else {
            form.val("peccancyClause-edit-form", {
                "tenantId": POPUP_DATA.tenantId,
                "status": true,
            });
        }
    }

    form.on('submit(peccancyClause-edit-form-submit)', function (data) {

        if (data.field.status == "on") {
            data.field.status = '1';
        } else {
            data.field.status = '0';
        }

        addOrUpdate(data.field);
        return false;
    });

    function addOrUpdate(data) {
        if (data.clauseId && data.clauseId.length > 0) {
            febs.postArray(ctx + 'peccancyClause/update', data, function () {
                layer.closeAll();
                febs.alert.success('修改成功');
                $('#febs-peccancyClauseRule').find('#query').trigger('click');
            });
        } else {
            febs.postArray(ctx + 'peccancyClause', data, function () {
                layer.closeAll();
                febs.alert.success('新增成功');
                $('#febs-peccancyClauseRule').find('#query').trigger('click');
            });
        }

    }
});